package org.learn.intermediate.com.exercise;

import java.util.HashSet;
import java.util.Objects;

public class HasSetExercise {
    public static void main(String[] args) {
        HashSet hashSet = new HashSet();
        hashSet.add(new Employee1("liming",18));
        hashSet.add(new Employee1("lihua",18));
        hashSet.add(new Employee1("liming",18));

        System.out.println("hashSet=" + hashSet );

    }
}
class Employee1 {
    private String name ;
    private int age ;

    public Employee1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Employee1 employee1 = (Employee1) o;
        return age == employee1.age && Objects.equals(name, employee1.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public String toString() {
        return "Employee1{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}